---@class RedRob.Bullet:RedRob.EffectBase
local Bullet = RedRob.CreateClass("Bullet","EffectBase")
function Bullet:OnCreate()
    RedRob.EffectBase.OnCreate(self)
    self.speed = 15
    self.moveTime = 0
    self.maxMoveTime = 0
    self.startPos = Vector3.GetCacheVec()
    self.targetPos = Vector3.GetCacheVec()
    self.skill = nil
end
function Bullet:OnDestroy()
    RedRob.EffectBase.OnDestroy(self)
    self.target = nil
    Vector3.ReturnToPool(self.startPos)
    Vector3.ReturnToPool(self.targetPos)
    self.startPos = nil
    self.targetPos = nil
end
function Bullet:Play()
    RedRob.EffectBase.Play(self)
    self.skill = self:GetSkill()
    self:InitMove()
end
function Bullet:InitMove()
    self.startPos:SetV(self.pos)
    local target = self:GetTarget()
    if target and not target:IsDead() then
        local skill = self:GetSkill()
        local x,y = skill:GetHitPos()
        self.targetPos:Set(x,y)
    else
        self:Die()
        return
    end
    self.moveTime = 0
    self.dir = self.targetPos - self.startPos
    self.dir:SetNormalize()
    --self.maxMoveTime = Vector3.Distance(self.startPos,self.targetPos)/self.speed
    --if self.maxMoveTime <= 0.000001 then
    --    self.maxMoveTime = 0.000001
   -- end
end
function Bullet:Update(dt)
    RedRob.EffectBase.Update(self,dt)
    if self.isDie then
        return
    end
    self.moveTime = self.moveTime + dt
    self.pos.x = self.pos.x + self.dir.x * self.speed * dt
    self.pos.y = self.pos.y + self.dir.y * self.speed * dt
    if self.skill and self.skill.actor and self.skill.actor:GetTarget() == nil then
        self:Die()
        return
    end
    local hitX,hitY = self.skill:GetHitPos()
    local isEnd = false
    if self.dir.x >= 0 and self.pos.x > hitX then
        isEnd = true
    elseif self.dir.x < 0 and self.pos.x < hitX then
        isEnd = true
    end
    self:SetObjPos(self.pos)
    if isEnd then
        self:Hit()
        self:Die()
        return
    end
end
function Bullet:Hit()
    self:GetSkill():Hit()
end